﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipmentSpotMasterVMs
{
    public partial class EquipmentSpotMasterListVM : BasePagedListVM<EquipmentSpotMaster_View, EquipmentSpotMasterSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipmentSpotMaster_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipmentSpotMaster_View>>{
                
                this.MakeGridHeader(x => x.EquipmentSpotMaster_Equipment).SetTitle(@Localizer["Page.关联设备"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_LineId).SetTitle(@Localizer["Page.所属产线"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_LineCode).SetTitle(@Localizer["Page.所属产线编号"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_MasterBarcode).SetTitle(@Localizer["Page.标件条码"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_SpotType).SetTitle(@Localizer["Page.标件类型"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_OpId).SetTitle(@Localizer["Page.所属工位"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_OpCode).SetTitle(@Localizer["Page.所属工位编号"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.EquipmentSpotMaster_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipmentSpotMaster_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentSpotMaster>()
                
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckEqual(Searcher.LineId, x=>x.ProductId)
                .CheckContain(Searcher.LineCode, x=>x.ProductCode)
                .CheckContain(Searcher.MasterBarcode, x=>x.MasterBarcode)
                .CheckEqual(Searcher.SpotType, x=>x.SpotType)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new EquipmentSpotMaster_View
                {
				    ID = x.ID,
                    
                    EquipmentSpotMaster_Equipment = x.Equipment.EquipName,
                    EquipmentSpotMaster_LineId = x.ProductId,
                    EquipmentSpotMaster_LineCode = x.ProductCode,
                    EquipmentSpotMaster_MasterBarcode = x.MasterBarcode,
                    EquipmentSpotMaster_SpotType = x.SpotType,
                    EquipmentSpotMaster_OpId = x.OpId,
                    EquipmentSpotMaster_OpCode = x.OpCode,
                    EquipmentSpotMaster_Active = x.Active,
                    EquipmentSpotMaster_CreateTime = x.CreateTime,
                    EquipmentSpotMaster_UpdateTime = x.UpdateTime,
                    EquipmentSpotMaster_CreateBy = x.CreateBy,
                    EquipmentSpotMaster_UpdateBy = x.UpdateBy,
                    EquipmentSpotMaster_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipmentSpotMaster_View: EquipmentSpotMaster
    {
        
        public string EquipmentSpotMaster_Equipment { get; set; }
        public long? EquipmentSpotMaster_LineId { get; set; }
        public string EquipmentSpotMaster_LineCode { get; set; }
        public string EquipmentSpotMaster_MasterBarcode { get; set; }
        public SpotTypeEnum? EquipmentSpotMaster_SpotType { get; set; }
        public long? EquipmentSpotMaster_OpId { get; set; }
        public string EquipmentSpotMaster_OpCode { get; set; }
        public bool? EquipmentSpotMaster_Active { get; set; }
        public DateTime? EquipmentSpotMaster_CreateTime { get; set; }
        public DateTime? EquipmentSpotMaster_UpdateTime { get; set; }
        public string EquipmentSpotMaster_CreateBy { get; set; }
        public string EquipmentSpotMaster_UpdateBy { get; set; }
        public bool EquipmentSpotMaster_IsValid { get; set; }

    }

}